import http from './http.js'
const request = {
  get(url, params) {
    const config = {
      method: 'get',
      url: url,
      crossdomain: true,
      headers: { 'content-type': 'application/json;charset=UTF-8' }
    }
    if (params) {
      config.data = JSON.stringify(params)
    }

    return http(config)
  },
  // /下载文件流
  getFile(url, params) {
    const config = {
      method: 'get',
      url: url,
      crossdomain: true,
      responseType: 'blob',

      timeout: 0,
      headers: { 'content-type': 'application/json;charset=UTF-8', ApplyNo: 'applyNo' }
    }
    if (params) {
      config.data = JSON.stringify(params)
    }
    return http(config)
  },
  post(url, params) {
    const config = {
      method: 'post',
      url: url,
      crossdomain: true,
      headers: { 'content-type': 'application/json;charset=UTF-8' }
    }

    if (params) {
      config.data = JSON.stringify(params)
    }
    return http(config)
  },
  postFiles(url, params) {
    const config = {
      method: 'post',
      url: url,
      crossdomain: true,
      timeout: 0,
      headers: {
        'content-type': 'multipart/form-data',
        'Access-Control-Allow-Origin': '*',
        ApplyNo: 'applyNo'
      }
    }
    if (params) {
      config.data = params
    }
    return http(config)
  },
  postFiles2(url, params, onUploadProgress) {
    const config = {
      method: 'post',
      url: url,
      crossdomain: true,

      timeout: 0,
      headers: {
        'content-type': 'multipart/form-data',
        'Access-Control-Allow-Origin': '*',
        ApplyNo: 'applyNo'
      },
      onUploadProgress
    }
    if (params) {
      config.data = params
    }
    return http(config)
  },
  put(url, params) {
    const config = {
      method: 'put',
      url: url,
      crossdomain: true,
      headers: { 'content-type': 'application/json;charset=UTF-8' }
    }
    if (params) {
      config.data = JSON.stringify(params)
    }
    return http(config)
  },
  delete(url, params) {
    const config = {
      method: 'delete',
      url: url,
      crossdomain: true,
      headers: { 'content-type': 'application/json;charset=UTF-8' }
    }
    if (params) {
      config.data = JSON.stringify(params)
    }
    return http(config)
  }
}
export default request
